package com.example.mypotiota_si.Activity;

import androidx.appcompat.app.ActionBar;
import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import androidx.viewpager.widget.ViewPager;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;

import com.example.mypotiota_si.Adapter.ListViewAdapter_fl;
import com.example.mypotiota_si.Adapter.ListViewAdapter_fl_rice;
import com.example.mypotiota_si.Datas.Dianpu;
import com.example.mypotiota_si.Datas.Dianpu_nr;
import com.example.mypotiota_si.Datas.FenLie;
import com.example.mypotiota_si.Datas.FenLie_nr;
import com.example.mypotiota_si.R;

import java.util.ArrayList;

import static androidx.recyclerview.widget.RecyclerView.*;

public class FenLeiActivity extends AppCompatActivity {
    RecyclerView fl_recyclerView,fl_rice_recyclerView;
    ListViewAdapter_fl_rice fl_rice_adapter;
    ListViewAdapter_fl fl_adapter;
    ArrayList<FenLie> fenLie;
    private ImageView fl_fh;
    LinearLayout fl_ss;
    ArrayList<Dianpu> dianpu;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_fen_lei);
        //隐藏标题栏
        ActionBar actionBar=getSupportActionBar();
        if (actionBar!=null){
            actionBar.hide();
        }
        //找到控件
        fl_recyclerView=findViewById(R.id.fl_recycler_view);
        fl_rice_recyclerView=findViewById(R.id.fl_rice_recycler_view);
        fl_fh=findViewById(R.id.fl_fh);
        fl_ss=findViewById(R.id.fl_ss);

        //添加数据
        init_Datas();

        //布局
        LinearLayoutManager layoutManager1=new LinearLayoutManager(this);
        layoutManager1.setOrientation(HORIZONTAL);
        fl_recyclerView.setLayoutManager(layoutManager1);
        fl_adapter=new ListViewAdapter_fl(fenLie);
        fl_recyclerView.setAdapter(fl_adapter);
        LinearLayoutManager layoutManager2=new LinearLayoutManager(this);
        layoutManager2.setOrientation(VERTICAL);
        fl_rice_recyclerView.setLayoutManager(layoutManager2);
        fl_rice_adapter=new ListViewAdapter_fl_rice(dianpu,FenLeiActivity.this);
        fl_rice_recyclerView.setAdapter(fl_rice_adapter);

        //点击事件
        init_dj();
    }
//添加数据
    private void init_Datas() {
        //添加分类数据
        fenLie=new ArrayList<>();
        for (int i = 0; i < FenLie_nr.fl_rice.length; i++) {
            FenLie fl=new FenLie();
            fl.fl_icon=FenLie_nr.fl_icon[i];
            fl.fl_rice=FenLie_nr.fl_rice[i];
            fenLie.add(fl);
        }
        //添加分类后的店铺数据
        dianpu=new ArrayList<>();
        for (int j = 0; j < Dianpu_nr.icon.length; j++) {
            Dianpu dp=new Dianpu();
            dp.dp_icon=Dianpu_nr.icon[j];
            dp.dp_name=Dianpu_nr.name[j];
            dp.dp_pf=Dianpu_nr.pf[j];
            dp.dp_ys=Dianpu_nr.ys[j];
            dp.dp_sj=Dianpu_nr.sj[j];
            dp.dp_qs=Dianpu_nr.qs[j];
            dp.dp_jj=Dianpu_nr.jj[j];
            dianpu.add(dp);
        }
    }

    //点击事件
    private void init_dj() {
        //点击返回
        fl_fh.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent=new Intent(FenLeiActivity.this,MainActivity.class);
                startActivity(intent);
            }
        });
        //点击搜索
        fl_ss.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent=new Intent(FenLeiActivity.this,SouSuoActivity.class);
                startActivity(intent);
            }
        });
    }
}
